import { defineStore } from 'pinia'
import { ref } from 'vue'
import { DialogQueue } from '@/utils/dialogQueue'

export const useConfirmDialogStore = defineStore('confirmDialog', () => {
    // 状态
    const dialogQueue = new DialogQueue()
    const currentDialog = ref(null)
    const isConfirmed = ref(false)

    // 显示确认对话框
    const show = (messageText, titleText) => {
        return dialogQueue.show({
            onLoaded: () => {
                isConfirmed.value = false
                currentDialog.value = {
                    title: titleText,
                    message: messageText
                }
            }
        })
    }

    // 确认操作
    const confirm = () => {
        isConfirmed.value = true
        dialogQueue.hide(true)
    }

    // 取消操作
    const cancel = () => {
        isConfirmed.value = false
        dialogQueue.hide(false)
    }

    return {
        isVisible: dialogQueue.isVisible,
        title: () => currentDialog.value?.title || '',
        message: () => currentDialog.value?.message || '',
        isConfirmed,
        show,
        confirm,
        cancel,
        getQueueLength: dialogQueue.getQueueLength.bind(dialogQueue),
        clearQueue: dialogQueue.clearQueue.bind(dialogQueue)
    }
}) 